package com.wmlive.hhvideo.heihei.personal.presenter;

import android.text.TextUtils;

import com.wmlive.hhvideo.common.base.BasePresenter;
import com.wmlive.hhvideo.common.network.HttpConstant;
import com.wmlive.hhvideo.heihei.beans.personal.ListOpusResponse;
import com.wmlive.hhvideo.heihei.beans.splash.InitCatchData;
import com.wmlive.hhvideo.heihei.personal.view.IPersonalProductView;
import com.wmlive.networklib.entity.DCNetObserver;

/**
 * Created by XueFei on 2017/6/2.
 * <p>
 * 作品
 */

public class PersonalProductPresenter extends BasePresenter<IPersonalProductView> {
    public PersonalProductPresenter(IPersonalProductView view) {
        super(view);
    }

    /**
     * 获取作品列表
     *
     * @param user_id
     * @param offset
     */
    public void getPersonaProductlList(long user_id, int offset) {
        String url = InitCatchData.userListUserOpus();
        if (!TextUtils.isEmpty(url) && null != viewCallback) {
            executeRequest(viewCallback.getClass().getSimpleName(), HttpConstant.TYPE_PERSONAL_PRODUCT_LIST, getHttpApi().getPersonalProductList(url, user_id, offset))
                    .subscribe(new DCNetObserver<ListOpusResponse>() {
                        @Override
                        public void onRequestDataReady(int requestCode, String message, ListOpusResponse response) {
                            if (null != viewCallback) {
                                viewCallback.handlePersonalProductListSucceed(response);
                            }
                        }

                        @Override
                        public void onRequestDataError(int requestCode, int serverCode, String message) {
                            if (null != viewCallback) {
                                viewCallback.handlePersonalProductListFailure(message);
                            }
                        }
                    });
            ;
        } else if (null != viewCallback) {
            viewCallback.handleNetError();
        }
    }

    /**
     * 重新设置IView
     *
     * @param view
     */
    public void setView(IPersonalProductView view) {
        if (null == viewCallback) {
            viewCallback = view;
        }
    }
}
